package cn.hnu.qq.client.controller;

import java.io.IOException;

import cn.hnu.qq.entity.User;
import cn.hnu.qq.entity.message.IpInfoMessage;
import cn.hnu.qq.entity.message.QueryIPInfoMessage;
import cn.hnu.qq.global.MessageType;

public class SingleChartController extends CenterController{

	private static SingleChartController instance = null;
	
	private SingleChartController(){};
	
	public static synchronized SingleChartController getInstance(){
		if(instance == null){
			instance = new SingleChartController();
		}
		return instance;
	}

	public void queryChartIpInfo(User user) {
		QueryIPInfoMessage message = new QueryIPInfoMessage();
		message.setAccount(user.getAcount());
		try {
			getOutput().writeObject(message);
			getOutput().flush();
			waitingMessageArriving(MessageType.IP_INFO);
			IpInfoMessage mes = (IpInfoMessage) get(MessageType.IP_INFO);
			user.setIp(mes.getIpAddr());
			user.setUserClientPort(mes.getClientListenPort());
			System.err.println(mes.getIpAddr());
			remove(MessageType.IP_INFO);
		} catch (IOException e) {
			System.err.println("queryChartIpInfo 错误");
			e.printStackTrace();
		}
	}

	
	
	
}
